//
//  HRUMShareTool.m
//  Hear
//
//  Created by mac on 2017/4/19.
//  Copyright © 2017年 mac. All rights reserved.
//

#import "HRUMShareTool.h"

#import <UMSocialCore/UMSocialCore.h>
#import <UShareUI/UShareUI.h>
@implementation HRUMShareTool
+(void)uMShareToolTitle:(NSString *)title andContentStr:(NSString *)contentStr andImage:(UIImage *)image andShareUrl:(NSString *)url isSeccess:(void(^)(BOOL isSeccess))isSeccess{
    [UMSocialUIManager setPreDefinePlatforms:@[@(UMSocialPlatformType_Qzone),@(UMSocialPlatformType_QQ),@(UMSocialPlatformType_WechatSession),@(UMSocialPlatformType_WechatTimeLine),@(UMSocialPlatformType_Sina)]];
    
    [UMSocialUIManager showShareMenuViewInWindowWithPlatformSelectionBlock:^(UMSocialPlatformType platformType, NSDictionary *userInfo) {
        //创建分享消息对象
        UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];
        
        //创建网页内容对象
        UMShareWebpageObject *shareObject = [UMShareWebpageObject shareObjectWithTitle:title descr:contentStr thumImage:image];
        //设置网页地址
        shareObject.webpageUrl = url;
        
        //分享消息对象设置分享内容对象
        messageObject.shareObject = shareObject;
        
        //调用分享接口
        [[UMSocialManager defaultManager] shareToPlatform:platformType messageObject:messageObject currentViewController:VIEWCCONTROLER completion:^(id data, NSError *error) {
            if (error) {
                UMSocialLogInfo(@"************Share fail with error %@*********",error);
                if([error.userInfo[@"message"] isEqualToString:@"APP Not Install"])
                {
                    [MBProgressHUD showMessage:@"您还没该客户端" finishBlock:nil];
                }
                isSeccess(NO);
                
            }else{
                if ([data isKindOfClass:[UMSocialShareResponse class]]) {
                    UMSocialShareResponse *resp = data;
                    //分享结果消息
                    UMSocialLogInfo(@"response message is %@",resp.message);
                    //第三方原始返回的数据
                    UMSocialLogInfo(@"response originalResponse data is %@",resp.originalResponse);
                    isSeccess(YES);

                }else{
                    UMSocialLogInfo(@"response data is %@",data);
                }
            }
            //        [self alertWithError:error];
        }];
        
    }];
}
@end
